package com.xunqi.mall.controller;

import com.github.pagehelper.PageInfo;
import com.xunqi.mall.service.ProductService;
import com.xunqi.mall.vo.ProductDetailVo;
import com.xunqi.mall.vo.ResponseVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description:
 * @Created with IntelliJ IDEA.
 * @author: 夏沫止水
 * @create: 2020-04-23 22:01
 **/
@RestController
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping(value = "/products")
    public ResponseVo<PageInfo> list(@RequestParam(value = "categoryId",required = false) Integer categoryId,
                                      @RequestParam(value = "pageNum",required = false) Integer pageNum,
                                      @RequestParam(value = "pageSize",required = false) Integer pageSize) {

        ResponseVo<PageInfo> listResponseVo = productService.list(categoryId, pageNum, pageSize);

        return listResponseVo;
    }


    @GetMapping(value = "/products/{productId}")
    public ResponseVo<ProductDetailVo> detail(@PathVariable("productId") Integer productId) {

        ResponseVo<ProductDetailVo> detail = productService.detail(productId);

        return detail;
    }

}
